package overlay;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;

import org.osmdroid.ResourceProxy;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.Overlay;

import mypack.openworld.Map;

public class CircleOverlay extends Overlay{
    GeoPoint center;
    float radius;
    int color = Color.BLACK,
    alpha = 30;
    Paint.Style paintStyle = Paint.Style.STROKE; // Рисовать только контур

    public void setPaintStyle(Paint.Style paintStyle) {
        this.paintStyle = paintStyle;
    }

    public void setAlpha(int alpha) {
        this.alpha = alpha;
    }

    public void setColor(int color) {
        this.color = color;
    }

    public CircleOverlay (Context context, GeoPoint geoPoint, float radius) {
        super(context);
        this.center = geoPoint;
        this.radius = radius;
    }

    public CircleOverlay(Context context) {
        super(context);
    }

    public CircleOverlay(ResourceProxy pResourceProxy) {
        super(pResourceProxy);
    }

    @Override
    protected void draw(Canvas canvas, MapView mapView, boolean shadow) {
        if (shadow) return;
        MapView.Projection mapViewProjection = mapView.getProjection();
        Point point = new Point();
        mapViewProjection.toMapPixels(center, point);
        float r = mapViewProjection.metersToEquatorPixels(radius);
        Paint circle = new Paint();
        circle.setColor(color);
        circle.setAlpha(alpha);
        circle.setStyle(paintStyle);

        canvas.drawCircle(point.x, point.y, r, circle);
    }
}
